<?php 
    session_start();
    if(!isset($_SESSION['username'])){
                header("Location: index.php");
                $_SESSION['log']=1;
    }
    else{
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php if(!isset($_POST['price_send'])){ ?>
        <form name="update" action="updatePrice.php" method="POST">

            Product
            <br>
            <input type="text" name="product" value="" />
            <br>
            
            Price
            <br>
            <input type="text" name="price" value="" />
            <br>

            <input type="submit" value="Update" name="button" />
        </form>
        <?php
            }
            
            if(isset($_POST['price_send'])){
                echo "Form Submitted!";
                try{
                $multicall;
                $j=0;
                foreach($_SESSION['stored_prod'] as $p){
                    $websites=$p['websites'];
                    $k=0;
                    foreach($websites as $w){
                        if($websites[$k]==$_SESSION['code']){
                            unset($websites[$k]);
                        }
                        $k++;
                    }
                    if($_POST["add_$j"]=='yes'){
                        array_push($websites, $_SESSION['code']);
                    }
                    $multicall[$j]=array('catalog_product.update',array($_POST["sku_$j"],array('price'=>$_POST["price_$j"],'websites'=>$websites),$_SESSION['username']));
                    $j++;
                    
                }
                
                    include 'config.php';
                    $proxy = new SoapClient($config['SOAPLocation']);
                    $sessionId = $proxy->login($config['SOAPUser'],$config['SOAPKey']);
                    $attributeSets = $proxy->call($sessionId, 'product_attribute_set.list');
                    $set = current($attributeSets);
                    $proxy->multiCall($sessionId, $multicall);
                    $proxy->endSession($sessionId);
                }
                catch(Exception $e){
                    echo "<b>Failure</b> $e";
                }
            }

        ?>
    </body>
</html>
<?php } ?>
